package com.zxt.dental_sys.model;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
 * @TableName sys_element_userinfo
 */
@TableName(value = "sys_element_userinfo")
@Data
public class SysElementUserinfo implements Serializable, UserDetails {
    /**
     * 用户pk（uuid 36）
     */
    @TableId
    private String userPk;

    /**
     * 用户登录账号
     */
    private String username;

    /**
     * 登录密码（加密共计60）
     */
    private String password;

    /**
     * 姓名
     */
    private String name;

    /**
     * 角色-虚拟
     */
    private String roles;

    /**
     * 电话
     */
    private String tel;

    /**
     * 邮箱地址
     */
    private String mail;

    /**
     * 年龄
     */
    private Integer age;

    /**
     * 公司
     */
    private String companys;

    /**
     * 性别
     */
    private String sexs;

    /**
     * 出生日期
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "Asia/Shanghai")
    private Date bornDate;

    /**
     * 用户头像url
     */
    private String headimgurl;

    /**
     * 是否删除
     */
    private Integer isDeleted;

    /**
     * 是否被禁用
     */
    private Integer isEnabled;

    /**
     * 创建时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date inputTime;

    /**
     * 更新时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date updateTime;

    /**
     * 身份证
     */
    private String identificationCard;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        SysElementUserinfo other = (SysElementUserinfo) that;
        return (this.getUserPk() == null ? other.getUserPk() == null : this.getUserPk().equals(other.getUserPk())) && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername())) && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword())) && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName())) && (this.getRoles() == null ? other.getRoles() == null : this.getRoles().equals(other.getRoles())) && (this.getTel() == null ? other.getTel() == null : this.getTel().equals(other.getTel())) && (this.getMail() == null ? other.getMail() == null : this.getMail().equals(other.getMail())) && (this.getAge() == null ? other.getAge() == null : this.getAge().equals(other.getAge())) && (this.getCompanys() == null ? other.getCompanys() == null : this.getCompanys().equals(other.getCompanys())) && (this.getSexs() == null ? other.getSexs() == null : this.getSexs().equals(other.getSexs())) && (this.getBornDate() == null ? other.getBornDate() == null : this.getBornDate().equals(other.getBornDate())) && (this.getHeadimgurl() == null ? other.getHeadimgurl() == null : this.getHeadimgurl().equals(other.getHeadimgurl())) && (this.getIsDeleted() == null ? other.getIsDeleted() == null : this.getIsDeleted().equals(other.getIsDeleted())) && (this.getIsEnabled() == null ? other.getIsEnabled() == null : this.getIsEnabled().equals(other.getIsEnabled())) && (this.getInputTime() == null ? other.getInputTime() == null : this.getInputTime().equals(other.getInputTime())) && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) && (this.getIdentificationCard() == null ? other.getIdentificationCard() == null : this.getIdentificationCard().equals(other.getIdentificationCard()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getUserPk() == null) ? 0 : getUserPk().hashCode());
        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getRoles() == null) ? 0 : getRoles().hashCode());
        result = prime * result + ((getTel() == null) ? 0 : getTel().hashCode());
        result = prime * result + ((getMail() == null) ? 0 : getMail().hashCode());
        result = prime * result + ((getAge() == null) ? 0 : getAge().hashCode());
        result = prime * result + ((getCompanys() == null) ? 0 : getCompanys().hashCode());
        result = prime * result + ((getSexs() == null) ? 0 : getSexs().hashCode());
        result = prime * result + ((getBornDate() == null) ? 0 : getBornDate().hashCode());
        result = prime * result + ((getHeadimgurl() == null) ? 0 : getHeadimgurl().hashCode());
        result = prime * result + ((getIsDeleted() == null) ? 0 : getIsDeleted().hashCode());
        result = prime * result + ((getIsEnabled() == null) ? 0 : getIsEnabled().hashCode());
        result = prime * result + ((getInputTime() == null) ? 0 : getInputTime().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        result = prime * result + ((getIdentificationCard() == null) ? 0 : getIdentificationCard().hashCode());
        return result;
    }

    @Override
    public String toString() {
        String sb = getClass().getSimpleName() +
                " [" +
                "Hash = " + hashCode() +
                ", userPk=" + userPk +
                ", username=" + username +
                ", password=" + password +
                ", name=" + name +
                ", roles=" + roles +
                ", tel=" + tel +
                ", mail=" + mail +
                ", age=" + age +
                ", companys=" + companys +
                ", sexs=" + sexs +
                ", bornDate=" + bornDate +
                ", headimgurl=" + headimgurl +
                ", isDeleted=" + isDeleted +
                ", isEnabled=" + isEnabled +
                ", inputTime=" + inputTime +
                ", updateTime=" + updateTime +
                ", identificationCard=" + identificationCard +
                ", serialVersionUID=" + serialVersionUID +
                "]";
        return sb;
    }

    /**
     * 进行角色权限列表获取
     *
     * @return
     */
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of(new SimpleGrantedAuthority(roles));
    }

    @Override
    public boolean isAccountNonExpired() {
        return UserDetails.super.isAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return UserDetails.super.isAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return UserDetails.super.isCredentialsNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return UserDetails.super.isEnabled();
    }
}